package com.zzl.car.controller;

import com.github.pagehelper.PageInfo;
import com.zzl.car.entity.CarBaseInfo;
import com.zzl.car.entity.Insurance;
import com.zzl.car.entity.User;
import com.zzl.car.service.ZzwCarDetailInfoService;
import com.zzl.car.service.ZzwInsuranceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@CrossOrigin
@RestController
public class ZzwInsuranceController {

    @Autowired
    private ZzwInsuranceService insuranceService;

    @GetMapping("/getAllInsurance")
    public PageInfo<Insurance> getAllInsurance(@RequestParam(value = "currentPage",defaultValue = "1") Integer currentPage){
        return insuranceService.getAllInsurance(currentPage);
    }

    /**
     * 查询键
     * @param name 保障名称
     * @param state 服务状态
     * @param currentPage
     * @return
     */
    @GetMapping("/searchInsurance")
    public PageInfo<Insurance> searchInsurance(@RequestParam("name")String name,
                                                 @RequestParam(value = "state",required = false)Integer state,
                                                 @RequestParam(value = "currentPage",defaultValue = "1") int currentPage){
        return insuranceService.searchInsurance(name,state,currentPage);
    }

    //获取用户信息
    @GetMapping("/getUserBaseInfo")
    public PageInfo<User> getUserBaseInfo(@RequestParam(value = "name",required = false)String name,
                                          @RequestParam(value = "gender",required = false)Integer gender,
                                          @RequestParam(value = "currentPage",defaultValue = "1") int currentPage){
        System.out.println(name);
        System.out.println(gender);
        return insuranceService.getUserBaseInfo(name,gender,currentPage);
    }

    // 删除息基础信
    @GetMapping("/deleteInsurance")
    public String deleteCarBaseInfo(@RequestParam("id") Integer id) {
        return insuranceService.deleteInsurance(id);
    }

    //添加保障信息
    @PostMapping("/addInsurance")
    public String addInsurance(@RequestBody Insurance in){
        return insuranceService.addInsurance(in);
    }

    //修改保障信息
    @PostMapping("/updateInsurance")
    public String updateInsurance(@RequestBody  Insurance in){
        return insuranceService.addInsurance(in);
    }
}
